package com.jtbd.dto.http;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.jtbd.domain.UserEmployee;
import com.jtbd.dto.db.UserEmployeeInfo;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.FutureOrPresent;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.Past;
import jakarta.validation.constraints.PastOrPresent;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;

import java.io.Serializable;
import java.util.Date;

@Schema(description = "用户员工信息")
@Data
public class UserEmployeeHttpDto {
    @Schema(description = "用户基础信息")
    @NotEmpty
    private UserInfoHttpDto userInfo;
    @Schema(description = "部门id")
    private Long departmentId;
    @Schema(description = "部门名称")
    private String departmentName;
    @Schema(description = "用户身份")
    private Integer userIdentity;
    @Schema(description = "机构id")
    private Long orgId;
    @Schema(description = "校区id")
    private Long campusId;
    @Schema(description = "上级id")
    private Long leaderId;
    @Schema(description = "员工状态")
    private Integer employeeStatus;
    @Schema(description = "入职时间")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @PastOrPresent(message = "入职时间不能大于当前时间")
    private Date joinTime;
    @Schema(description = "离职时间")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date quitTime;

    public static UserEmployeeInfo getUserEmployeeInfo(UserEmployeeHttpDto info) {
        UserEmployeeInfo userEmployeeInfo = new UserEmployeeInfo();
        userEmployeeInfo.setUserInfo(UserInfoHttpDto.getUserInfo(info.userInfo));
        UserEmployee employee = new UserEmployee();
        employee.setDepartmentId(info.departmentId);
        employee.setEmployeeDepartmentIdentity(info.userIdentity);
        employee.setCampusId(info.campusId);
        employee.setOrgId(info.orgId);
        employee.setLeaderId(info.leaderId);
        employee.setEmployeeStatus(info.employeeStatus);
        userEmployeeInfo.setUserEmployee(employee);
        return userEmployeeInfo;
    }

    public static UserEmployeeHttpDto getUserEmployeeHttpDtoInfo(UserEmployeeInfo userEmployeeInfo) {
        UserEmployeeHttpDto info = new UserEmployeeHttpDto();
        info.userInfo = UserInfoHttpDto.getUserInfoHttpDto(userEmployeeInfo.getUserInfo());
        info.departmentId = userEmployeeInfo.getUserEmployee().getDepartmentId();
        info.userIdentity = userEmployeeInfo.getUserEmployee().getEmployeeDepartmentIdentity();
        info.campusId = userEmployeeInfo.getUserEmployee().getCampusId();
        info.orgId = userEmployeeInfo.getUserEmployee().getOrgId();
        info.leaderId = userEmployeeInfo.getUserEmployee().getLeaderId();
        info.employeeStatus = userEmployeeInfo.getUserEmployee().getEmployeeStatus();
        info.joinTime = userEmployeeInfo.getUserEmployee().getJoinTime();
        info.quitTime = userEmployeeInfo.getUserEmployee().getQuitTime();
        return info;
    }
}
